package com.jy.admin.rest.admin;

import com.fqgj.common.utils.MD5;
import com.jy.admin.auth.anno.VisitorAccessible;
import com.jy.admin.auth.request.LoginRequest;
import com.jy.admin.auth.request.ModifyRequest;
import com.jy.admin.auth.service.LoginApplication;
import com.jy.admin.auth.vo.AccountInfoVo;
import com.jy.admin.auth.vo.LoginInfoVo;
import com.jy.bo.common.conf.api.ApiResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created with IntelliJ IDEA.
 * User: binary (mr.vencnet@gmail.com)
 * Date: 2020-08-11
 * Time: 10:48
 */
@RestController
@RequestMapping("/admin")
public class LoginController {

    @Autowired
    private LoginApplication loginApplication;

    @RequestMapping(value = "/login")
    @VisitorAccessible
    public ApiResponse<LoginInfoVo> login(@RequestBody LoginRequest request) {
        LoginInfoVo info = loginApplication.login(request.getAccount(), request.getPassword());
        return new ApiResponse<>(info);
    }

    @RequestMapping(value = "/modify")
    @VisitorAccessible
    public ApiResponse<String> modify(@RequestBody ModifyRequest request) {
        loginApplication.modify(request.getOldPwd(), request.getNewPwd(),request.getConfirmPwd());

        return new ApiResponse<>();
    }

    @RequestMapping(value = "/info")
    @VisitorAccessible
    public ApiResponse<AccountInfoVo> getAccountInfo() {
        AccountInfoVo vo = loginApplication.getAccountInfo();
        return new ApiResponse<>(vo);
    }

    public static void main(String[] args) {
        String abc = MD5.md5("123456");
        System.err.println(abc);
    }
}
